package com.qiwx.pigeon.presenter;

import com.qiwx.pigeon.base.BasePresenter;
import com.qiwx.pigeon.base.IBaseView;
import com.qiwx.pigeon.data.network.ApiManager;
import com.qiwx.pigeon.data.network.BaseResponse;
import com.qiwx.pigeon.data.network.ResponseSubscriber;
import com.qiwx.pigeon.data.params.FarmPageParam;
import com.qiwx.pigeon.data.params.GoOutParam;
import com.qiwx.pigeon.data.vo.GoOutBean;
import com.qiwx.pigeon.data.vo.pageinfo.PageInfo;
import com.qiwx.pigeon.data.vo.stock.SupplierBean;
import com.qiwx.pigeon.viewinterface.ICommonView;
import com.qiwx.pigeon.viewinterface.IGoOutView;

import java.lang.ref.WeakReference;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @description
 * @Author qiwx
 * @Date 2020-04-26 09:59
 * 供应商
 **/
public class SupplierPresenter extends BasePresenter<ICommonView<SupplierBean>> {

    public SupplierPresenter(WeakReference<ICommonView<SupplierBean>> from) {
        super(from);
    }

    public SupplierPresenter(ICommonView from) {
        super(from);
    }

    // 添加供应商
    public void addSupplier(SupplierBean params) {
        ApiManager.getApiServer().addSupplier(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse response) {
                        getView().onAddSuccess(response);

                    }
                });
    }

    //获取供应商
    public void getSupplierList(FarmPageParam params) {
        ApiManager.getApiServer().getSupplierList(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse<PageInfo<SupplierBean>>>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse<PageInfo<SupplierBean>> response) {
                        getView().onQueryListSuccess(response.data);
                    }

                });
    }

    //删除记录
    public void deleteSupplier(SupplierBean params) {
        ApiManager.getApiServer().deleteSupplier(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResponseSubscriber<BaseResponse>(true) {
                    @Override
                    public IBaseView getIView() {
                        return getView();
                    }

                    @Override
                    public void onSuccess(BaseResponse response) {
                        getView().onDeleteSuccess(response);

                    }
                });
    }

}
